1. #define F_CPU 16000000UL
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4. #include <avr/interrupt.h>
  5. /******************************************************************************/
  6. int main(void)
  7. {
  8. cli();
  9. DDRD &= ~_BV(DDD0); // set as input
  10. PORTD |= _BV(PORTD0); // enable pull-up
  11. DDRB |= _BV(DDD5);
  12. PORTB |= _BV(PORTB5); // initialize to high
  13. PCICR |= _BV(PCIE2); // set PCIE2 to enable PCMSK2 scan
  14. PCMSK2 |= _BV(PCINT16); // set PCINT16 to trigger an interrupt on state change
  15. sei(); // turn on interrupts
  16. while (1);
  17. }
  18. /******************************************************************************/
  19. ISR (PCINT2_vect)
  20. {
  21. PINB |= _BV(PINB5);
  22. _delay_ms(5);
  23. }
  24. /******************************************************************************/